//
//  CAIEmptyViewControllerKit.h
//  CAIEmptyViewController
//
//  Created by 海参 on 2022/6/28.
//
//
// 2022.06.30 fix实现，imageView图标不显示；ui加载时机错位不对；
// 移除了webView跳转；toast改为内置不依赖外面；
// 2022.07.01 重构API，解决网络是否可访问的bug；
// 2022.07.05 networkErrorHelp.html 图片改为网络图片，增加全局配置属性：networkErrorHelpHtmlPath、ookErrorSolutionActionBlock，修复设置view的frame的bug


#ifndef CAIEmptyViewControllerKit_h
#define CAIEmptyViewControllerKit_h

#import "ZXEmptyViewController.h"
#import "CAIEmptyViewGlobalConfig.h"


#endif /* CAIEmptyViewControllerKit_h */









/////////////////--例如--////////////////////
/*
- (void)configEmptyView{
    EmptyCustomCenterButtonAppearance *appearance =[CAIEmptyViewGlobalConfig sharedInstance].customButtonAppearance;
    appearance.actionBtnBackgroundColor = [UIColor caiColorWithHexString:@"#FF6A00"];
    appearance.actionBtnCornerRadius = 18;
    appearance.actionBtnSize = CGSizeMake(128, 36);
    appearance.actionBtnMarginTop = 16;
    appearance.actionBtnFont = [UIFont zx_systemFontOfSize:16 weight:UIFontWeightMedium];
}
 */
//例1:列表
/*
 #import <CAIEmptyViewKit/CAIEmptyViewKit.h>
@interface SearchResultsController ()<
 UICollectionViewDelegateFlowLayout,
 UICollectionViewDataSource,
 ZXEmptyViewControllerDelegate>
 
@property (nonatomic, strong) ZXEmptyViewController *emptyViewController;
@end
 
- (void)setUI
{
    self.tableView.backgroundColor = WYUISTYLE.colorBGgrey;
    self.tableView.tableFooterView = [[UIView alloc] init];
    
    [self.tableView registerNib:[UINib nibWithNibName:Xib_OrderProductCell bundle:nil] forCellReuseIdentifier:reuse_Cell];
    [self.tableView registerNib:[UINib nibWithNibName:Xib_OrderCellFooterView bundle:nil] forHeaderFooterViewReuseIdentifier:reuse_FooterView];
    [self.tableView registerNib:[UINib nibWithNibName:Xib_OrderCellHeaderView bundle:nil] forHeaderFooterViewReuseIdentifier:reuse_HeaderView];
}
 
- (ZXEmptyViewController *)emptyViewController
{
    if (!_emptyViewController) {
        
        _emptyViewController = [[ZXEmptyViewController alloc] init];
        _emptyViewController.delegate = self;
    }
    return _emptyViewController;
}
 //自己移除；
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [self.emptyViewController removeEmptyViewInContainerViewConroller];
    [self.tableView.mj_header beginRefreshing];
}
 
- (void)headerRefresh
{
    WS(weakSelf);
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [weakSelf requestHeaderData];
    }];
}
 
- (void)requestHeaderData
{
    WS(weakSelf);
    [HsOrderManagementApi getOrderListWithRoleType:[WYUserDefaultManager getUserTargetRoleType] orderStatus:0 search:self.searchBar.text pageNo:1 pageSize:@(10) success:^(id data,PageModel *pageModel) {
        
        [weakSelf.dataMArray removeAllObjects];
        [weakSelf.dataMArray addObjectsFromArray:data];
        [weakSelf.tableView reloadData];
        weakSelf.pageNo = 1;
        [weakSelf.tableView.mj_header endRefreshing];
        [weakSelf.tableView.mj_footer endRefreshing];
        [weakSelf footerWithRefreshingMorePage:[pageModel.totalPage integerValue]>1?YES:NO];
        [weakSelf.emptyViewController addEmptyViewInController:weakSelf hasLocalData:weakSelf.dataMArray.count>0?YES:NO emptyImage:[UIImage imageNamed:@"无人接单"] emptyTitle:@"没有搜到相关订单信息"];
        
    } failure:^(NSError *error) {
        
        [weakSelf.tableView.mj_header endRefreshing];
        [weakSelf.emptyViewController addEmptyErrorViewInController:weakSelf hasLocalData:weakSelf.dataMArray.count>0?YES:NO error:error];
    }];
}
    
    

- (void)footerWithRefreshingMorePage:(BOOL)flag
{
    if (!flag)
    {
        if (self.tableView.mj_footer)
        {
            self.tableView.mj_footer = nil;
        }
        return;
    }
    WS(weakSelf);
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
        [weakSelf requestFooterData];
    }];
}
    
- (void)requestFooterData
{
    WS(weakSelf);
    [HsOrderManagementApi getOrderListWithRoleType:[WYUserDefaultManager getUserTargetRoleType] orderStatus:0 search:self.searchBar.text pageNo:_pageNo+1 pageSize:@(10) success:^(id data,PageModel *pageModel) {
        
        [weakSelf.dataMArray addObjectsFromArray:data];
        [weakSelf.tableView reloadData];
        [weakSelf.tableView.mj_footer endRefreshing];
        weakSelf.pageNo ++;
        if (weakSelf.dataMArray.count==totalCount)
        {
            weakSelf.tableView.mj_footer = nil;
        }
    } failure:^(NSError *error) {
        
        [weakSelf.tableView.mj_footer endRefreshing];
        [MBProgressHUD zx_showError:[error localizedDescription] toView:weakSelf.view];
    }];
}


- (void)zxEmptyViewTouchAndActionWithController:(ZXEmptyViewController *)emptyView
{
    [self.tableView.mj_header beginRefreshing];
}

*/

/*
 // 分页用next一个字段控制。
 
 ///红包可用商品列表
 - (void)requestHeaderData
 {
     WS(weakSelf);
     [RedpacketModelHttpAPI postCouponsWithGoodsListWithRedpaperId:self.redpacketId next:nil success:^(id  _Nullable data) {
         
         if (data) {
             HomeGoodsModel *model = (HomeGoodsModel*)data;
             [weakSelf.dataMArray removeAllObjects];
             [weakSelf.dataMArray addObjectsFromArray:model.records];
             weakSelf.next = model.next;
             [weakSelf footerWithRefreshingMorePage:([model.next integerValue]>0)?YES:NO];
         }
         if (weakSelf.dataMArray.count>0) {
             weakSelf.topView.hidden = NO;
         }
         [weakSelf.collectionView reloadData];
         [weakSelf.collectionView.mj_header endRefreshing];
         [weakSelf.collectionView.mj_footer endRefreshing];
         [weakSelf.emptyViewController addEmptyViewInController:weakSelf hasLocalData:weakSelf.dataMArray.count>0?YES:NO emptyImage:[UIImage imageNamed:@"empty_noData"] emptyTitle:@"暂无可用商品信息"];
     } failure:^(NSError * _Nullable error) {
         
         [weakSelf.collectionView.mj_header endRefreshing];
         [weakSelf.emptyViewController addEmptyErrorViewInController:weakSelf hasLocalData:weakSelf.dataMArray.count>0?YES:NO error:error];
     }];
 }

 
 #pragma mark -加载更多
 - (void)requestFooterData
 {
     WS(weakSelf);
     [RedpacketModelHttpAPI postCouponsWithGoodsListWithRedpaperId:self.redpacketId next:self.next success:^(id  _Nullable data) {
         
          HomeGoodsModel *model = (HomeGoodsModel*)data;
          [weakSelf.dataMArray addObjectsFromArray:model.records];
          [weakSelf.collectionView reloadData];
          [weakSelf.collectionView.mj_footer endRefreshing];
          
          weakSelf.next = model.next;
          if (!model.next || [model.next integerValue] == 0)
          {
              weakSelf.collectionView.mj_footer = nil;
          }
         
     } failure:^(NSError * _Nullable error) {
         
         [CAIProgressHUD toastMessage:[error localizedDescription]];
         [weakSelf.collectionView.mj_footer endRefreshing];
     }];
 }
 */


//例2:model模型数据
/*
- (void)setData
{
[MBProgressHUD showLottieToView:self.view];
    WS(weakSelf);
    [UserModelHttpAPI postInfoWithSuccess:^(id  _Nullable data) {
        
        [MBProgressHUD zx_hideHUDForView:weakSelf.view];
        weakSelf.userModel = data;
        [weakSelf.emptyViewController removeEmptyViewInContainerViewConroller];
        [weakSelf releadData];
        
    } failure:^(NSError * _Nullable error) {
        
        [MBProgressHUD zx_hideHUDForView:weakSelf.view];
        [weakSelf.emptyViewController addEmptyErrorViewInController:weakSelf hasLocalData:weakSelf.userModel?YES:NO error:error];

    }];
}
*/
